# 地铁路线
import time
china_ditie = {
    '北京':{
        "一号线":["四惠",'大望路','天安门','西单'],
        "二号线":["北京站",'朝阳门','东直门','西直门'],
        "三号线":["国贸",'三元桥','知春路','巴沟']
    },
    '上海':{
        "四号线":["徐家汇",'人民广场','延长路','共康路'],
        "五号线":["东昌路",'静安寺','江苏路','呼兰路'],
        "六号线":["宝山路",'赤峰路','曹杨路','宜山路']
    },
    '广州':{
        "七号线":["东山口",'农讲所','烈士陵园','公元前'],
        "八号线":["黄边",'纪念堂','三元里','白云公园'],
        "九号线":["沙河顶",'北京路','一德路','文化公园']
    }
}

start = True
city_list = []
xian_list = []
print('\033[31;1m欢迎访问地铁查询系统\033[1m'.center(40,'='))
while start:
    print(''.center(36,'='))
    for v,city in enumerate(china_ditie.keys(),1):
        print(v, city)
        city_list.append(city)
    print("退出 \033[31;1mq\033[1m")
    print("".center(36,'='))
    c_city = input("请选择您要查询的城市编号：")
    print("".center(36,"="))
    if c_city.isdigit():
        c_city = int(c_city)
        if c_city <= len(city_list) and c_city > 0 :
            while start:
                if city_list[c_city - 1] in china_ditie.keys():
                    for x, xian in enumerate(china_ditie[city_list[c_city - 1]].keys(), 1):
                        print(x, xian)
                        xian_list.append(xian)
                    print("返回上级\033[31;1mb\033[1m,退出\033[31;1mq\033[1m")
                    print("".center(36,'='))
                    c_xian = input("请选择你要查询的路线：")
                    print("".center(36,'='))
                    if c_xian == 'b' or c_xian == 'B':
                        del city_list[:]
                        del xian_list[:]
                        break
                    elif c_xian == 'q' or c_xian == 'Q':
                        start = False
                    elif c_xian.isdigit():
                        c_xian = int(c_xian)
                        if c_xian <= len(xian_list) and c_xian > 0:
                            while start:
                                for name in china_ditie[city_list[c_city - 1]][xian_list[c_xian - 1]]:
                                    print(name)
                                print("返回上级\033[31;1mb\033[1m,退出\033[31;1mq\033[1m")
                                print("".center(36,'='))
                                c_n = input("请输入你需要的操作：")
                                if c_n == 'b' or c_n =='B':
                                    del xian_list[:]
                                    break
                                elif c_n == 'q' or c_n == 'Q':
                                    start = False
                                else:
                                    print("\033[31;1m输入错误请重新输入，退出请按\033[31;1mq\033[1m")
                                    time.sleep(1)
                        else:
                            del xian_list[:]
                            print("\033[31;1m没有此路线或者输入错误！\033[1m")
                            time.sleep(1)

                    else:
                        del xian_list[:]
                        print("\033[31;1m输入错误，请输入数字！\033[1m")
                        time.sleep(1)

                else:
                    del  city_list[:]
                    print("\033[31;1m没有此城市或者输入错误！\033[1m")
                    time.sleep(1)
        else:
            del city_list[:]
            print("\033[31;1m没有此城市或者输入错误！\033[1m")
            time.sleep(1)